<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>homework3</title>
</head>
<body>
    <pre>
        import math
        posx,posy=0,0
        str = input('')
        while str!='STOP':
            dirlist=str.split(' ')
            direction=dirlist[0]
            step=int(dirlist[1])
            if direction == 'UP':
                posy+=step
            elif direction == 'DOWN':
                posy-=step
            elif direction == 'RIGHT':
                posx+=step
            elif direction == 'LEFT':
                posx-=step
            str  =input('')
        print(round(math.sqrt(posx**2+posy**2)))
    </pre>
</body>
</html>